<?php
/**
 * Gets value of configuration parameter
 * @param string $k parameter name
 * @return mixed parameter value
 */
function _cfg($k)
{
    static $cfg = array();
if (!$cfg){
        // get common settings
        require_once('config/server.php');
        require_once('config/common.php');
        require_once('config/systems.php');

        // get modules settings
        $mods = glob($cfg['path'] . '_inc/mod/*', GLOB_ONLYDIR);
        foreach ($mods as $mod)
          	if (file_exists($mod.'/config/config.php')){
        		include $mod.'/config/config.php';
        	}
        
    }    
    if ($cfg[$k])
        return $cfg[$k];
    if (strpos($k,".") !== false){
        $t =explode(".", $k);
        if (isset($cfg[$t[0]]) && is_array($cfg[$t[0]]) && isset($cfg[$t[0]][$t[1]]))
            return $cfg[$t[0]][$t[1]];
    }
}

/**
 * Prints human readable info about $param
 *
 * @param mixed $param info to display
 * @param bool $isDie
 */
function _d($param, $isDie=false)
{
    echo '<hr><pre><xmp>';
    if (is_bool($param))
    	$param = $param? "True" : "False";
    print_r($param);
    echo '</xmp></pre><hr>';
    if ($isDie)
        die();
}


function grubber($url){
	$data = file_get_contents($url);
	$data = iconv("windows-1251", "UTF-8", $data);
	$data = str_replace(array("\r\n", "\r", "\n",'\t'), ' ', $data); 
	$data =  preg_replace('/\s{2,}/',' ',$data);
	return $data;
}

function grubber2($url){
	$head = array(
		"Accept"	=> "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
		"Accept-Encoding"	=>	"gzip, deflate",
		"Accept-Language" 	=>	"ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3",
		"Cache-Control"  	=>	"max-age=0",
		"Connection"		=>"keep-alive",
		/*"Cookie"			=>" MarketGidStorage=%7B%22C37559%22%3A%7B%22page%22%3A5%2C%22time%22%3A1364598656174%7D%2C%220%22%3A%7B%22svspr%22%3A%22%22%2C%22svsds%22%3A10%2C%22TejndEEDj%22%3A%22MTM2NDU5ODY0NTI0OTM3NTU5Mzkz%22%7D%2C%22C37573%22%3A%7B%22page%22%3A5%2C%22time%22%3A1364598656568%7D%7D",*/
		"Host"				=>	"www.loveread.ec",
		"If-Modified-Since"	=>	"Wed, 19 Sep 2012 12:49:50 GMT",
		"User-Agent"		=> "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0"
		
	);
	/*$curl = curl_init();
	curl_setopt ($curl, CURLOPT_URL, $url);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($curl, CURLOPT_HTTPHEADER, $head);
	*/
	$data = file_get_contents($url);
	
	//$data = curl_exec($curl);

	$data = iconv("windows-1251", "UTF-8", $data);
	$data = str_replace(array("\r\n", "\r", "\n",'\t'), ' ', $data); 
	$data =  preg_replace('/\s{2,}/',' ',$data);
	return $data;
}